/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.amu.wmi.kino.visualjavafx.nodes.objects.helpers;

import org.openide.nodes.Children;
import org.openide.nodes.Node;
import pl.edu.amu.wmi.kino.visualjavafx.model.api.ModelChangeListener;
import pl.edu.amu.wmi.kino.visualjavafx.model.api.ModelChangeNotifier;
import pl.edu.amu.wmi.kino.visualjavafx.nodes.factory.NodeFactory;

/**
 *
 * @author psychollek
 */
public class JavaFxChildren<T> extends Children.Keys<T>{

    @Override
    protected final Node[] createNodes(Object obj) {

        Node retNode = NodeFactory.generateFrom(obj);

        Node n = this.getNode();

        while (n!= null){
            ModelChangeListener mcl = n.getLookup().lookup(ModelChangeListener.class);
            if (mcl != null){
                ModelChangeNotifier mcn = retNode.getLookup().lookup(ModelChangeNotifier.class) ;
                mcn.addModelChangeListener(mcl);
                return new Node[]{retNode};
            }else{
                n = n.getParentNode();
            }
        }
        return new Node[]{retNode};

    }

}
